import { UI_Layer, UI_Listen } from '../../config/ui_def'
import { WX_AD_CONFIG, Sdk_Platform, VIVO_AD_CONFIG, OPPO_AD_CONFIG, Ad_Type } from '../../frame/constants';
import util from '../tool/util';
cc.Class({
    extends: cc.Component,

    properties: {
        win_node: cc.Node,          // 胜利抬头
        fail_node: cc.Node,         // 失败抬头

        quit_node: cc.Node,         // 退出抬头
        restart_node: cc.Node,      // 重开抬头
        ad_get_node: cc.Node,       // 广告奖励
        get_node: cc.Node,          // 直接获得奖励
        reward_content_node: cc.Node,// 格子

        star_node: cc.Node,          // 星星节点 
        cover_sprite: cc.Sprite,     // 角色Pose
        tip_sprite: cc.Sprite,      // 提示图片
        game_res: false,           // 胜负
        adNode: cc.Node,            //广告icon
        bannerNode: cc.Node,          //banner节点    
        btns_node: cc.Widget,
        center_node: cc.Widget,
        win_widge: cc.Widget,
        fail_widge: cc.Widget,
        tip_node: cc.Node,
    },
    initPage() {
        let addNum = 5 - this.reward_content_node.childrenCount
        let reward_prefab = he.load.get("uimod/bagItem")
        this.star_ani_list = []
        for (let i = 0; i < addNum; i++) {
            let reward_node = cc.instantiate(reward_prefab)
            this.reward_content_node.addChild(reward_node)
        }
    },
    updatePage(param) {
        he.voice.stopMusic()
        // status 控制胜负
        this.game_res = param.status
        this.tip_node.active = false
        this.closeGameButtons()
        this.updatePassReward()
        this.reward_list = []
        this.taskCheck9002()
        this.taskCheck9003()
        if (param.status) {
            he.voice.playEffect("win", "voice")
            this.win_node.active = true
            this.fail_node.active = false
            this.isWin = 1
            this.updateWin()
            this.updatePassReward(true)
            this.adSwitch(true)
            this.checkGuide()
        } else {
            he.voice.playEffect("fail", "voice")
            this.win_node.active = false
            this.fail_node.active = true
            this.isWin = 0
            this.updateFail()
            this.updatePassReward()
            this.adSwitch(true)
        }
        this.isShowAd = false
        switch (common.sdk_env) {
            case Sdk_Platform.WECHAT:
                this.checkTrail()
                this.fuckWXshowAd()
                let ver_info = he.local.getJson('ver_info')
                if (ver_info.banner_mistake) {
                    this.btns_node.bottom = 290
                    this.center_node.top = 300
                    this.btns_node.updateAlignment()
                    this.center_node.updateAlignment()
                } else {
                    this.btns_node.bottom = 350
                    this.center_node.top = 300
                    this.btns_node.updateAlignment()
                    this.center_node.updateAlignment()
                    this.bannerNode.height = 250
                    let bannerNodeWidge = this.bannerNode.getComponent(cc.Widget)
                    bannerNodeWidge.bottom = 0
                    bannerNodeWidge.updateAlignment()
                    this.bannerInit()
                }
                break
            case Sdk_Platform.VIVO:
                this.win_widge.top = 100
                this.win_widge.updateAlignment()
                this.fail_widge.top = 100
                this.fail_widge.updateAlignment()
                this.center_node.top = 200
                this.center_node.updateAlignment()
                this.btns_node.node.getChildByName('Restart').setPosition(0, -20)
                this.btns_node.node.getChildByName('AdReward').setPosition(0, -20)
                this.btns_node.node.getChildByName('Quit').setPosition(0, 100)
                this.btns_node.node.getChildByName('GetReward').setPosition(0, 100)
                break
            default:
                this.btns_node.bottom = 350
                this.center_node.top = 300
                this.btns_node.updateAlignment()
                this.center_node.updateAlignment()
                break
        }
        this.uploadGameRes()
        gg.eventManager.emit('playground', { type: UI_Listen.PLGD_ENDAD })
    },

    checkTrail() {
        if (gg.data.isTrail) {
            let team = he.local.getJson('team', 'user')
            for (let i = 0; i < team.length; i++) {
                if (team[i].id == gg.data.trailID) {
                    team.splice(i, 1)
                    break
                }
            }
            he.local.setJson('team', team, 'user')
        }
    },

    checkGuide() {
        let guideList = he.local.getJson('guideList', 'user')
        if (!guideList[5]) {
            guideList[5] = 1
            he.local.setJson('guideList', guideList, 'user')
        } else {
            // this.adSwitch(true)
        }
    },

    fuckWXshowAd() {
        gg.uiManager.addPage(UI_Layer.Pop, {
            name: 'hotAdPage',
            cover: true,
            cover_opacity: 200
        })
        gg.uiManager.addPage(UI_Layer.Pop, {
            name: 'bottomAd',
        })
    },

    closeUI() {
        for (let i = this.star_ani_list.length - 1; i >= 0; i--) {
            this.star_ani_list[i].stop()
            this.star_ani_list.splice(i, 1)
        }

        for (let i = (this.adNode.children.length); i > 0; i--) {

            let spt = this.adNode.children[i - 1].getComponent('scrollAd')
            if (spt) {
                spt.clearItem()
            }
            he.pool.putElement('scrollAd', this.adNode.children[i - 1])
        }
        if (this.tipTween) {
            this.tipTween.stop()
            this.tipTween = null
        }

        if (this.sch1) {
            this.unschedule(this.sch1, 0.5)
            this.sch1 = null
        }
        if (this.sch2) {
            this.unschedule(this.sch2, 0.5)
            this.sch2 = null
        }
        this.hideBanner()
    },
    adSet(config) {
        // console.log(config)
        if (config.isOpen) {
            if (config.isOpen) {
                let pre = he.pool.getElement('scrollAd')
                pre.parent = this.adNode
                pre.getComponent('scrollAd').init(config.creatives, 1, true)
            }
        }
    },

    adSwitch(status) {
        if (status) {
            let guideList = he.local.getJson('guideList', 'user')
            if (!guideList[6]) {
                return
            }
            switch (common.sdk_env) {
                case Sdk_Platform.WECHAT:
                    if (!common.showAd) return
                    let ver_info = he.local.getJson('ver_info')
                    he.ad.getTdAdJson(WX_AD_CONFIG.tmIcon[7], this.adSet.bind(this))
                    break
                case Sdk_Platform.VIVO:
                    // this.adNode.name = VIVO_AD_CONFIG.bannerId[0]
                    // he.ad.changeBanner(status, this.adNode)
                    // he.ad.interstitialShow()
                    break
                case Sdk_Platform.OPPO:
                    gg.uiManager.addPage(UI_Layer.Msg, {
                        name: 'chayeAdFakeOPPO',
                        isShowAd: true,
                        isShowBanner: false,
                        adIndex: 3,
                        position: cc.Vec2(0, -500)
                    })
                    break
                case Sdk_Platform.UC:
                    let num4 = Math.ceil(Math.random() * 10)
                    // if (num4 < 5) {
                    he.ad.showBanner()
                    // } else {
                    //     he.ad.showInterstitialAd()
                    // }
                    break
                case Sdk_Platform.HUAWEI:
                    let showPit = false
                    gg.uiManager.addPage(UI_Layer.Msg, {
                        name: 'hwAdPage',
                        cover: false,
                        isShowAd: true,
                        pit: showPit,
                        adType: Ad_Type.INSERT,
                        position: 0
                    })
                    break
            }
        } else {
            //  关掉广告
            switch (common.sdk_env) {
                case Sdk_Platform.WECHAT:
                    break
                case Sdk_Platform.VIVO:
                    // this.adNode.name = VIVO_AD_CONFIG.bannerId[0]
                    // he.ad.changeBanner(status, this.adNode)
                    break
                case Sdk_Platform.OPPO:
                    gg.uiManager.closePage(UI_Layer.Msg, 'chayeAdFakeOPPO')
                    break
                case Sdk_Platform.UC:
                    he.ad.hideBanner()
                    break
                case Sdk_Platform.HUAWEI:
                    if (gg.uiManager.getPage(UI_Layer.Msg, 'hwAdPage')) {
                        gg.uiManager.closePage(UI_Layer.Msg, 'hwAdPage')
                    }
                    break
            }
        }
    },

    hideBanner() {
        switch (common.sdk_env) {
            case Sdk_Platform.WECHAT:
                he.ad.changeBanner(false, this.bannerNode)
                break
        }
    },

    bannerInit() {
        switch (common.sdk_env) {
            case Sdk_Platform.WECHAT:
                this.bannerNode.name = WX_AD_CONFIG.bannerId[0]
                /// 显示
                he.ad.changeBanner(true, this.bannerNode)
                break
        }

    },

    // 角色击杀
    taskCheck9003() {
        let taskGrp = he.local.getJson('task', 'user')
        if (taskGrp && taskGrp.length > 0) {
            for (let item in gg.data.deathDict) {
                // console.log(item)
                if (item == undefined) {
                    continue
                }
                let oneRoleEnd = item.split('#')[1].split('_')[0]
                for (let i = 0; i < taskGrp.length; i++) {
                    //同类型的关卡，且
                    if (taskGrp[i].type == 9003 && taskGrp[i].param == parseInt(oneRoleEnd)) {
                        let addNum = taskGrp[i].num + gg.data.deathDict[item].length
                        if (addNum <= taskGrp[i].need) {
                            taskGrp[i].num = addNum
                        } else {
                            taskGrp[i].num = taskGrp[i].need
                        }
                    }
                }
            }
            he.local.setJson('task', taskGrp, 'user')
        }
    },
    // 击杀怪物
    taskCheck9002() {
        let taskGrp = he.local.getJson('task', 'user')
        if (taskGrp && taskGrp.length > 0) {
            for (let item in gg.data.classDict) {
                for (let i = 0; i < taskGrp.length; i++) {
                    //同类型的关卡，且
                    if (taskGrp[i].type == 9002 && taskGrp[i].param == parseInt(item)) {
                        let addNum = taskGrp[i].num + gg.data.classDict[item]
                        if (addNum <= taskGrp[i].need) {
                            taskGrp[i].num = addNum
                        } else {
                            taskGrp[i].num = taskGrp[i].need
                        }
                    }
                }
            }
            he.local.setJson('task', taskGrp, 'user')
        }

    },
    // 上传游戏数据
    uploadGameRes() {
        let info = he.local.getJson('user') || null
        let gameoverInfo = {
            pass_id: gg.data.pass_id,
            winOrLose: this.isWin,
            uid: info.uid,
            openid: info.openid,
            damage: gg.data.damegeDict,
            deathList: gg.data.deathDict,
            time: gg.data.gameSec,
            classDict: gg.data.classDict,
            version: he.db.getTable("version")
        }
        switch (common.sdk_env) {
            case Sdk_Platform.WECHAT:
                wx.cloud.callFunction({
                    name: 'gameOverInfo',
                    success: res => {
                        console.log("请求云函数成功", res)
                    },
                    fail: res => {
                    },
                    data: gameoverInfo
                })
                break
            case Sdk_Platform.VIVO:
                cloud.callFunction({
                    name: 'gameOverInfo',
                    data: gameoverInfo
                }).then(res => {
                    // console.log(res)
                }).catch(err => {
                    console.log(err)
                })
                break
            case Sdk_Platform.OPPO:
                cloud.callFunction({
                    name: 'gameOverInfo',
                    data: gameoverInfo
                }).then(res => {
                    // console.log(res)
                }).catch(err => {
                    console.log(err)
                })
                break
            case Sdk_Platform.UC:
                cloud.callFunction({
                    name: 'gameOverInfo',
                    data: gameoverInfo
                }).then(res => {
                    // console.log(res)
                }).catch(err => {
                    console.log(err)
                })
                break
            case Sdk_Platform.HUAWEI:
                cloud.callFunction({
                    name: 'gameOverInfo',
                    data: gameoverInfo
                }).then(res => {
                    // console.log(res)
                }).catch(err => {
                    console.log(err)
                })
                break
            case Sdk_Platform.DEBUG:
                break
        }
    },
    updatePassReward(showNum) {
        let passInfo = he.db.getData('Pass', gg.data.pass_id)
        let reward_list = passInfo.reward.split("#")
        this.reward_list = []
        for (let j = 0; j < this.reward_content_node.children.length; j++) {
            this.reward_content_node.children[j].active = false
        }
        for (let i = 0; i < reward_list.length; i++) {
            this.reward_content_node.children[i].active = true
            let reward_param = reward_list[i].split('_')
            let itemScript = this.reward_content_node.children[i].getComponent('bagItem')
            let item_id = parseInt(reward_param[0])
            itemScript.initInfo(item_id)
            if (showNum) {
                let min = parseInt(reward_param[1])
                let max = parseInt(reward_param[2])
                let add_random = parseInt((max - min) * Math.random()) + min
                itemScript.num = add_random
                this.reward_list.push({
                    id: item_id,
                    num: add_random
                })
            }
        }

    },
    // 更新胜利
    updateWin() {
        this.openRwardButtons()
        let pass_info = he.db.getData('Pass', gg.data.pass_id)
        // 封面更换
        let damegeRole = {}
        for (let key in gg.data.damegeDict) {
            let key_list = key.split("#")
            if (key_list[1]) {
                let role_param = key_list[1].split("_")
                if (damegeRole[role_param[0]]) {
                    damegeRole[role_param[0]] += gg.data.damegeDict[key]
                } else {
                    damegeRole[role_param[0]] = gg.data.damegeDict[key]
                }
            }
        }
        let firstRole = {
            id: 0,
            value: 0
        }
        for (let key in damegeRole) {
            if (damegeRole[key] > firstRole.value) {
                firstRole.id = key
                firstRole.value = damegeRole[key]
            }
        }
        let overrole_info = he.db.getDataByArgs("Role", { roleId: firstRole.id })

        this.cover_sprite.spriteFrame = he.load.get('overPage', cc.SpriteAtlas, 'plist').getSpriteFrame(`pose_` + overrole_info.roleType)
        this.tip_sprite.spriteFrame = he.load.get('overPage', cc.SpriteAtlas, 'plist').getSpriteFrame(`text_qczj`)


        // 关卡数据记录
        let score_con = pass_info.scoreCon
        let score_param = pass_info.scoreParam.split("/")
        let star = 0
        // console.log("得星条件" + score_con)

        if (score_con == 1) {
            for (let i = 0; i < score_param.length; i++) {
                if (gg.data.hurtCount < parseInt(score_param[i])) {
                    star++
                } else {
                    break
                }
            }
        }
        else if (score_con == 2) {
            let number_of_attacks = pass_info.numberOfAttacks.split("/")
            let star_new = 0
            // console.log("score_param.length"+score_param.length)
            for (let i = 0; i < score_param.length; i++) {
                // console.log("i"+i)
                // console.log("掉血量:"+gg.data.hurtCount,"   分数要求血量",parseInt(score_param[i]),gg.data.hurtCount < parseInt(score_param[i]))
                if (gg.data.hurtCount < parseInt(score_param[i])) {
                    star++
                } else {
                    //break
                }
                // console.log("受攻击次数:"+gg.data.number_of_attacks,"   分数要求受攻击次数",parseInt(number_of_attacks[i]),gg.data.number_of_attacks < parseInt(number_of_attacks[i]))
                if (gg.data.number_of_attacks < parseInt(number_of_attacks[i])) {
                    star_new++
                } else {
                    //break
                }
            }
            // console.log("星星数量",star,"星星数量",star_new)
            star > star_new ? star = star_new : null
        }



        let passList = he.local.getJson('pass_list', 'user')
        if (passList && passList.length > 0) {
            let isHave = false
            for (let i = 0; i < passList.length; i++) {
                if (passList[i].id == gg.data.pass_id) {
                    passList[i].star = star > passList[i].star ? star : passList[i].star
                    isHave = true
                    break
                }
            }
            if (!isHave) {
                passList.push({ id: gg.data.pass_id, record: gg.data.hurtCount, star: star })
            }
        } else {
            passList.push({ id: gg.data.pass_id, record: gg.data.hurtCount, star: star })
        }
        this.updateStar(star)
        he.local.setJson('pass_list', passList, 'user')
        this.unlockRoleCheck()
    },
    unlockRoleCheck() {
        let pass_list = he.local.getJson('pass_list', 'user')
        // let lockList = he.db.getTable('Lock')
        let passLen = pass_list.length
        if (passLen >= 0 && passLen < 10) {

        } else if (passLen >= 10 && passLen < 15) {
            this.addNewRole(1002)
            // gg.uiManager.addTip('解锁新角色了')
        } else if (passLen >= 25 && passLen < 30) {
            this.addNewRole(1003)
        } else if (passLen >= 50 && passLen < 55) {
            this.addNewRole(1004)
        } else if (passLen >= 75 && passLen < 80) {
            this.addNewRole(1005)
        }
    },
    addNewRole(roleId) {
        let team = he.local.getJson('team', 'user')
        let isHave = false
        for (let i = 0; i < team.length; i++) {
            if (team[i].id == roleId) {
                isHave = true
                return
            }
        }
        if (!isHave) {
            let newRole = { id: roleId, order: -1, equips: [1, 0, 0, 0], hand: 0, }
            team.push(newRole)
        }
        he.local.setJson('team', team, 'user')
    },
    // 更新失败
    updateFail() {
        this.openGameButtons()
        this.cover_sprite.spriteFrame = he.load.get('overPage', cc.SpriteAtlas, 'plist').getSpriteFrame(`pose_fail`)
        this.tip_sprite.spriteFrame = he.load.get('overPage', cc.SpriteAtlas, 'plist').getSpriteFrame(`text_zaijiezaili`)
    },
    updateStar(star) {
        if (this.game_res) {
            for (let i = this.star_ani_list.length - 1; i >= 0; i--) {
                this.star_ani_list[i].stop()
                this.star_ani_list.splice(i, 1)
            }

            for (let i = 0; i < 3; i++) {
                let star_node = this.star_node.getChildByName(`star_bg_${i}`)
                star_node.children[0].active = true
                star_node.children[0].scale = 0
            }
            for (let i = 0; i < 3; i++) {
                let star_node = this.star_node.getChildByName(`star_bg_${i}`)
                if (star > i) {
                    let starAni = cc.tween(star_node.children[0])
                        .delay(1 * i)
                        .to(0.5, { scale: 2 }, { easing: `elasticOut` })
                        .to(0.5, { scale: 1 })
                        .start()
                    this.star_ani_list.push(starAni)
                }
            }
        }
    },
    // 更新胜利后信息
    openRwardButtons() {
        this.ad_get_node.active = true
        this.get_node.active = true
    },
    // 打开按钮
    openGameButtons() {
        this.ad_get_node.active = false
        this.get_node.active = false
        this.quit_node.active = true
        this.restart_node.active = true
    },
    // 关闭所有按钮
    closeGameButtons() {
        this.quit_node.active = false
        this.restart_node.active = false
        this.ad_get_node.active = false
        this.get_node.active = false
    },
    // 获得广告收益
    getAdReward() {
        switch (common.sdk_env) {
            case Sdk_Platform.WECHAT:
                let guideList = he.local.getJson('guideList', 'user')
                if (guideList) {
                    if (!guideList[2]) {
                        util.adFakeTip()
                        he.ad.showVideo(this.adFunc.bind(this))
                    } else {
                        this.adwxServer()
                    }
                } else {
                    util.adFakeTip()
                    he.ad.showVideo(this.adFunc.bind(this))
                }
                break
            case Sdk_Platform.VIVO:
                he.ad.showVideo(this.adFunc.bind(this))
                break
            case Sdk_Platform.OPPO:
                he.ad.showVideo(OPPO_AD_CONFIG.videoId[0], this.adFunc.bind(this))
                break
            case Sdk_Platform.UC:
                he.ad.showVideo(this.adFunc.bind(this))
                break
            case Sdk_Platform.HUAWEI:
                he.ad.showVideo(this.adFunc.bind(this))
                break
            default:
                this.adFunc()
                break
        }
    },

    adwxServer() {
        if (!this.isShowAd) {
            this.isShowAd = true
            let ver_info = he.local.getJson('ver_info')
            if (ver_info.banner_mistake) {
                this.sch1 = this.scheduleOnce(this.bannerInit, 0.5)
                this.sch2 = this.scheduleOnce(this.hideBanner, 3)
            } else {
                switch (common.sdk_env) {
                    case Sdk_Platform.WECHAT:
                        util.adFakeTip()
                        he.ad.showVideo(this.adFunc.bind(this))
                        break
                }
            }
        } else {
            util.adFakeTip()
            he.ad.showVideo(this.adFunc.bind(this))
        }
    },

    adFunc() {
        for (let i = 0; i < this.reward_list.length; i++) {
            let itemScript = this.reward_content_node.children[i].getComponent('bagItem')
            itemScript.initInfo(this.reward_list[i].id)
            itemScript.num = this.reward_list[i].num    //*5
            gg.data.addItem(parseInt(this.reward_list[i].id), parseInt(this.reward_list[i].num * 5))
        }
        this.rewardPageInit(true)
        this.tip_node.active = true
        this.tipTween = cc.tween(this.tip_node)
            .repeatForever(
                cc.tween()
                    .to(0.25, { opacity: 255, scale: 2.5 })
                    .to(0.25, { scale: 2 })
                    .to(0.25, { opacity: 255, scale: 2.5 })
                    .to(0.25, { scale: 2 })
                    .delay(1.5)
            )
            .start()
        switch (common.sdk_env) {
            case Sdk_Platform.WECHAT:
                break
            case Sdk_Platform.VIVO:
                he.local.click(`vivo_video_GameOverPage`)
                break

        }
        this.openGameButtons()
        this.adAdd()
    },

    rewardPageInit(isFive) {
        let rewardGrp = []
        let numIndex = 1
        if (isFive) {
            numIndex = 5
        } else {
            numIndex = 1
        }
        for (let i = 0; i < this.reward_list.length; i++) {
            rewardGrp.push(`${this.reward_list[i].id}_${this.reward_list[i].num * numIndex}`)
        }
        gg.uiManager.addPage(UI_Layer.Load, {
            name: 'rewardPage',
            itemGrp: rewardGrp,
            cover: true,
            close: true,
            gameOver: true,
        })
        let num = Math.ceil(Math.random() * 10)
        if (num > 3) {
            console.log(num)
            //啥也不做
        } else {
            // vivo弹插页
            switch (common.sdk_env) {
                case Sdk_Platform.WECHAT:
                    break
                case Sdk_Platform.VIVO:
                    gg.eventManager.emit('playground', { type: UI_Listen.PLGD_VIDEO }, () => {
                        gg.uiManager.addPage(UI_Layer.Msg, {
                            name: 'chayeAdFake',
                            isShowAd: true,
                            isShowBanner: false,
                            pageName: 'gameOver'
                        })
                    })
                    break
                case Sdk_Platform.OPPO:

                    break
                default:
                    break
            }
        }
    },

    adAdd() {
        let taskGrp = he.local.getJson('task', 'user')
        if (taskGrp && taskGrp.length > 0) {
            for (let j = 0; j < taskGrp.length; j++) {
                if (taskGrp[j].type == 9001) {
                    if (taskGrp[j].num < taskGrp[j].need) {
                        taskGrp[j].num += 1
                    }
                    break
                }
            }
        }
        he.local.setJson('task', taskGrp, 'user')
    },
    // 获得收益
    getReward() {
        switch (common.sdk_env) {
            case Sdk_Platform.WECHAT:
                let guideList = he.local.getJson('guideList', 'user')
                if (guideList) {
                    if (!guideList[2]) {
                        this.onebetGet()
                    } else {
                        this.rewardwxServer()
                    }
                } else {
                    this.onebetGet()
                }
                break
            default:
                this.onebetGet()
                break
        }
    },

    rewardwxServer() {
        if (!this.isShowAd) {
            this.isShowAd = true
            switch (common.sdk_env) {
                case Sdk_Platform.WECHAT:
                    let ver_info = he.local.getJson('ver_info')
                    if (ver_info.banner_mistake) {
                        this.sch1 = this.scheduleOnce(this.bannerInit, 0.5)
                        this.sch2 = this.scheduleOnce(this.hideBanner, 3)
                    } else {
                        this.onebetGet()
                    }
                    break
                default:
                    this.onebetGet()
                    break
            }

        } else {
            this.onebetGet()
        }
    },

    onebetGet() {
        for (let i = 0; i < this.reward_list.length; i++) {
            let itemScript = this.reward_content_node.children[i].getComponent('bagItem')
            itemScript.initInfo(this.reward_list[i].id)
            itemScript.num = this.reward_list[i].num
            gg.data.addItem(parseInt(this.reward_list[i].id), parseInt(this.reward_list[i].num))
        }
        this.rewardPageInit(false)
        this.openGameButtons()
    },
    // 重启游戏
    restartGame() {
        gg.uiManager.addPage(UI_Layer.Load, {
            name: "LoadCover",
            in: true,
            restart: true,
            scene: 'Playground'
        })
        // he.voice.stopMusic("voice/playground")
        gg.eventManager.emit('loadcover', UI_Listen.CLOSE_LOAD_COVER)
        this.uiBase.closePage()
    },
    exitGame() {
        let guideList = he.local.getJson('guideList', 'user')
        if (guideList) {
            if (!guideList[2]) {
                gg.uiManager.addPage(UI_Layer.Load, {
                    name: "LoadCover",
                    in: true,
                    scene: 'Main'
                })
            } else {

                // switch (common.sdk_env) {
                //     case Sdk_Platform.WECHAT:
                //         if (!common.showAd) {
                //             gg.uiManager.addPage(UI_Layer.Load, {
                //                 name: "LoadCover",
                //                 in: true,
                //                 scene: 'Main'
                //             })
                //         } else {
                //             this.hideBanner()
                //             gg.uiManager.addPage(UI_Layer.Load, {
                //                 name: "fakeRank",
                //             })
                //         }

                //         break
                //     default:
                gg.uiManager.addPage(UI_Layer.Load, {
                    name: "LoadCover",
                    in: true,
                    scene: 'Main'
                })
                // break
                // }
            }
        } else {
            gg.uiManager.addPage(UI_Layer.Load, {
                name: "LoadCover",
                in: true,
                scene: 'Main'
            })
        }

        this.uiBase.closePage()
    }
});
